<?php

/**
 * 
 * @desc String is numeric validation rule 
 * @author Barbushin Sergey http://www.linkedin.com/in/barbushin
 * 
 */
class DaBase_Valid_Numeric extends DaBase_Valid_Rule {
	
	protected $min;
	protected $max;
	protected $errorText = 'require to be numeric';
	
	public function __construct($min=null, $max=null, $errorText=null) {
		$this->min = $min;
		$this->max = $max;
		$this->setErrorText($errorText);
	}

	protected function validate() {
		if(!is_numeric($this->value)) {
			return false;
		}
		if($this->min !== null && $this->value < $this->min) {
			return false;
		}
		if($this->max !== null && $this->value > $this->max) {
			return false;
		}
		return true;
	}
}
